package com.baylor.activity;

import com.baylor.R;
import com.baylor.common.ConstantValue;
import com.baylor.utils.SharedPreferencesUtil;
import com.baylor.widget.HeaderBarView;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends Activity {
	
	private HeaderBarView mHeadBarView;
	private EditText mEdtAccount;
	private EditText mEdtPwd;
	private Dialog mLoadingDialog;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_login);

		findView();
		init();
	}
	
	private void findView() {
		mHeadBarView = (HeaderBarView) findViewById(R.id.headBarView);
		mEdtAccount = (EditText) findViewById(R.id.edt_account);
		mEdtPwd = (EditText) findViewById(R.id.edt_pwd);
	}
	
	private void init() {
		
		mHeadBarView.setTitle( getString(R.string.login) );

        String account = SharedPreferencesUtil.getString(this, ConstantValue.USER_INFO, ConstantValue.ACCOUNT);
        if( account != null && !"".equals(account) ) {
            mEdtAccount.setText(account);
        }
	}
	
	/**
	 * 登录
	 * @param view
	 */
	public void onCommitLogin(View view) {
		final String userAccount = mEdtAccount.getText().toString().trim();
		String userPwd = mEdtPwd.getText().toString().trim();
		
		if( "".equals(userAccount) || "".equals(userPwd) ) {
			Toast.makeText(this, getString(R.string.account_pwd_empty), Toast.LENGTH_SHORT).show();
			return;
		}
		
		// 在此处登录???

	}
	
	private void initLoadingDialog() {
		mLoadingDialog = new Dialog(LoginActivity.this, R.style.AlertStyle);
		mLoadingDialog.setContentView(R.layout.alert_loading);
		Window window = mLoadingDialog.getWindow();
		WindowManager.LayoutParams params = window.getAttributes();  
        params.dimAmount = 0f;  
        window.setAttributes(params);
		mLoadingDialog.show();
	}
	
	/**
	 * 去注册
	 * @param view
	 */
	public void toRegist(View view) {

	}
	

}
